Crate file_format
source ·Expand description
Crate for determining the file format of a given file or stream.
It provides a variety of functions for identifying a wide range of file formats, including ZIP, Compound File Binary (CFB), Extensible Markup Language (XML) and much more.
It checks the signature of the file to determine its format and intelligently employs specific readers when available for accurate identification. If the signature is not recognized, the crate falls back to the default file format, which is Arbitrary Binary Data (BIN).
Examples
Determines from a file:
use file_format::{FileFormat, Kind};
let format = FileFormat::from_file("fixtures/document/sample.pdf")?;
assert_eq!(format, FileFormat::PortableDocumentFormat);
assert_eq!(format.name(), "Portable Document Format");
assert_eq!(format.short_name(), Some("PDF"));
assert_eq!(format.media_type(), "application/pdf");
assert_eq!(format.extension(), "pdf");
assert_eq!(format.kind(), Kind::Document);
Determines from bytes:
use file_format::{FileFormat, Kind};
let format = FileFormat::from_bytes(&[0xFF, 0xD8, 0xFF]);
assert_eq!(format, FileFormat::JointPhotographicExpertsGroup);
assert_eq!(format.name(), "Joint Photographic Experts Group");
assert_eq!(format.short_name(), Some("JPEG"));
assert_eq!(format.media_type(), "image/jpeg");
assert_eq!(format.extension(), "jpg");
assert_eq!(format.kind(), Kind::Image);
Crate features
All features below are disabled by default.
Ecosystem features
serde
- Adds the ability to serialize and deserialize aFileFormat
andKind
using serde.
Reader features
These features enable the detection of file formats that require a specific reader for identification.
reader
- Enables all reader features.reader-asf
- Enables Advanced Systems Format (ASF) based file formats detection.reader-cfb
- Enables Compound File Binary (CFB) based file formats detection.- 3D Studio Max (MAX)
- Autodesk Inventor Assembly (IAM)
- Autodesk Inventor Drawing (IDW)
- Autodesk Inventor Part (IPT)
- Autodesk Inventor Presentation (IPN)
- Microsoft Excel Spreadsheet (XLS)
- Microsoft PowerPoint Presentation (PPT)
- Microsoft Project Plan (MPP)
- Microsoft Publisher Document (PUB)
- Microsoft Software Installer (MSI)
- Microsoft Visio Drawing (VSD)
- Microsoft Word Document (DOC)
- Microsoft Works 6 Spreadsheet (XLR)
- Microsoft Works Database (WDB)
- Microsoft Works Word Processor (WPS)
- SolidWorks Assembly (SLDASM)
- SolidWorks Drawing (SLDDRW)
- SolidWorks Part (SLDPRT)
- StarCalc (SDC)
- StarChart (SDS)
- StarDraw (SDA)
- StarImpress (SDD)
- StarMath (SMF)
- StarWriter (SDW)
- WordPerfect Document (WPD)
- WordPerfect Graphics (WPG)
reader-ebml
- Enables Extensible Binary Meta Language (EBML) based file formats detection.reader-exe
- Enables MS-DOS Executable (EXE) based file formats detection.reader-mp4
- Enables MPEG-4 Part 14 (MP4) based file formats detection.reader-pdf
- Enables Portable Document Format (PDF) based file formats detection.reader-rm
- Enables RealMedia (RM) based file formats detection.reader-txt
- Enables Plain Text (TXT) detection when the file format is not recognized by its signature. Please note that this feature only detects files containing ASCII/UTF-8-encoded text.reader-xml
- Enables Extensible Markup Language (XML) based file formats detection. Please note that these file formats may be detected without the feature in certain cases.- AbiWord (ABW)
- AbiWord Template (AWT)
- Additive Manufacturing Format (AMF)
- Advanced Stream Redirector (ASX)
- Atom
- Digital Asset Exchange (DAE)
- Extensible 3D (X3D)
- Extensible Stylesheet Language Transformations (XSLT)
- FictionBook (FB2)
- GPS Exchange Format (GPX)
- Geography Markup Language (GML)
- Keyhole Markup Language (KML)
- MPEG-DASH Manifest (MPD)
- Mathematical Markup Language (MathML)
- MusicXML
- Really Simple Syndication (RSS)
- Scalable Vector Graphics (SVG)
- Simple Object Access Protocol (SOAP)
- Tiled Map XML (TMX)
- Tiled Tileset XML (TSX)
- Timed Text Markup Language (TTML)
- Training Center XML (TCX)
- Universal Subtitle Format (USF)
- XML Localization Interchange File Format (XLIFF)
- XML Shareable Playlist Format (XSPF)
- draw.io (DRAWIO)
reader-zip
- Enables ZIP-based file formats detection.- 3D Manufacturing Format (3MF)
- Adobe Integrated Runtime (AIR)
- Android Package (APK)
- Autodesk 123D (123DX)
- Circuit Diagram Document (CDDX)
- Design Web Format XPS (DWFX)
- Electronic Publication (EPUB)
- Enterprise Application Archive (EAR)
- FictionBook Zipped (FBZ)
- Fusion 360 (F3D)
- InDesign Markup Language (IDML)
- Java Archive (JAR)
- Keyhole Markup Language Zipped (KMZ)
- Microsoft Visual Studio Extension (VSIX)
- MusicXML Zipped (MXL)
- Office Open XML Document (DOCX)
- Office Open XML Drawing (VSDX)
- Office Open XML Presentation (PPTX)
- Office Open XML Spreadsheet (XLSX)
- OpenDocument Database (ODB)
- OpenDocument Formula (ODF)
- OpenDocument Formula Template (OTF)
- OpenDocument Graphics (ODG)
- OpenDocument Graphics Template (OTG)
- OpenDocument Presentation (ODP)
- OpenDocument Presentation Template (OTP)
- OpenDocument Spreadsheet (ODS)
- OpenDocument Spreadsheet Template (OTS)
- OpenDocument Text (ODT)
- OpenDocument Text Master (ODM)
- OpenDocument Text Master Template (OTM)
- OpenDocument Text Template (OTT)
- OpenRaster (ORA)
- SpaceClaim Document (SCDOC)
- Sun XML Calc (SXC)
- Sun XML Calc Template (STC)
- Sun XML Draw (SXD)
- Sun XML Draw Template (STD)
- Sun XML Impress (SXI)
- Sun XML Impress Template (STI)
- Sun XML Math (SXM)
- Sun XML Writer (SXW)
- Sun XML Writer Global (SGW)
- Sun XML Writer Template (STW)
- Universal Scene Description Zipped (USDZ)
- Web Application Archive (WAR)
- Windows App Package (APPX)
- XAP
- XPInstall (XPI)
- iOS App Store Package (IPA)
Enums
- A file format.
- A kind of
FileFormat
.